﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CompareIndexStructure.cs" company="SmartPlan">
//   SmartPlan 2011
// </copyright>
// <summary>
//   The compare index structure.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DbDiff.Common.Comparer
{
    using System;
    using DataAccess;
    using Helper;
    using Model;

    /// <summary>
    /// The compare index structure.
    /// </summary>
    public class CompareIndexStructure : CompareDataStructure
    {
        /// <summary>
        /// The Fields.
        /// </summary>
        public readonly CompareIndexKeyStructure Fields;

        /// <summary>
        /// Initializes a new instance of the <see cref="CompareIndexStructure"/> class. 
        /// The compare index structure.
        /// </summary>
        /// <param name="databaseCompare">
        /// Compare object
        /// </param>
        /// <param name="objectType">
        /// Object  type
        /// </param>
        public CompareIndexStructure(DatabaseCompare databaseCompare, DatabaseObjectTypes objectType) : base(databaseCompare, objectType)
        {
            this.dv1Name = databaseCompare.DatabaseInfoBaseLeft.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.AllIndexByTableName);
            this.dv1Key = databaseCompare.DatabaseInfoBaseLeft.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.AllIndexByKey);
            this.dv2Name = databaseCompare.DatabaseInfoBaseRight.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.AllIndexByTableName);
            this.dv2Key = databaseCompare.DatabaseInfoBaseRight.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.AllIndexByKey);

            this.Fields = new CompareIndexKeyStructure(databaseCompare, DatabaseObjectTypes.IndexKey);
            this.rowColumnName = DataRowCompareIndex.Index;
        }

        /// <summary>
        /// Compare index keys
        /// </summary>
        public override void CompareChildRows()
        {
            this.errorString += (this.errorString != string.Empty ? "," : string.Empty) +
                                this.Fields.Compare(this.cmp.CurrentField);
        }
    }
}